package netWorkPrograming.tcp.tcp01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/5/27
 * 需求1：客户端与服务端可以建立连接 ； 服务端接收一条消息，客户端发送一条消息
 */
public class ServerDemo {
    public static void main(String[] args) {
        try {
            System.out.println("----------------服务端--------------");
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("服务端已开启");
            Socket socket = serverSocket.accept();
            System.out.println("与客户端建立连接");
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String s=null;
            while((s=br.readLine())!=null){
                System.out.println(InetAddress.getLocalHost()+"/t说："+s);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
